﻿///////////////////////////////////////////////////////////////////////////////
// 文件名： D3D9Render.hpp
// 作者：   671643387@qq.com
// 日期：   2015年11月1日 下午6:15:15
// 简介：   
///////////////////////////////////////////////////////////////////////////////

#if !defined(GRAPHICS_RENDER_DX9_D3D9RENDER_HPP_)
#define GRAPHICS_RENDER_DX9_D3D9RENDER_HPP_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <d3dx9.h>

#include <graphics/EventDelegate.hpp>
#include <graphics/graphics/render/Render.hpp>

#include "D3D9RenderWindow.hpp"

namespace dx9
{
    namespace render
    {
        class D3D9Render : public ::graphics::graphics::render::Render
        {
        public:
            D3D9Render(void);
            virtual ~D3D9Render(void);

        public:
            virtual bool Initialize(void);
            virtual void Shutdown(void);
            virtual void SetEventDelegate(::graphics::EventDelegate* delegate);
            virtual void SetScene(::graphics::graphics::ScenePtr scene);
            virtual bool BeginFrame(void);
            virtual void EndFrame(void);
            virtual void RenderFrame(void);
            virtual void ClearColor(::graphics::byte r, ::graphics::byte g, ::graphics::byte b, ::graphics::byte a);
            virtual void UseCamera(::graphics::graphics::scenenode::Camera::stProperties& properties);
            virtual ::graphics::graphics::component::BufferPtr CreateBuffer(::graphics::graphics::component::MeshRenderer::stProperties& properties);

        private:
            bool CreateRenderWindow_(void);
            bool InitializeDX9_(HWND hWnd);
            void CheckCaps_(D3DPRESENT_PARAMETERS& d3dpp, int& vp);

        private:
            LPDIRECT3D9 d3d9Impl_;
            LPDIRECT3DDEVICE9 d3d9DevImpl_;

            D3D9RenderWindowPtr renderWin_;

            ::graphics::EventDelegate* eventDelegate_;
            ::graphics::graphics::ScenePtr scene_;
        };
    }
}

#endif //GRAPHICS_RENDER_DX9_D3D9RENDER_HPP_
